package com.qdu.sort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SortMapper extends Mapper<LongWritable, Text, TwoSort.IntPair,IntWritable> {
    private final TwoSort.IntPair intkey = new TwoSort.IntPair();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, TwoSort.IntPair, IntWritable>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split(",");
        int left = 0;
        int right = 0;
        if(line.contains("id")){
            return;
        }
        left = Integer.parseInt(split[3]);
        right = Integer.parseInt(split[5]);
        intkey.set(right, left);
        context.write(intkey, new IntWritable(left));
    }
}
